#!/bin/sh
#
# Launch Station, data sink and data source with associated parameters.
#
#		
# (by H. Schulz 2011, edit by S. Phieler 2012)
#

printUsage() {
    echo  "Usage: $0 <team> <station> <message> <data source port> <data source intervall> <data sink port> <network-interface> <multicast-address> <multicast-port> <run-time>"
}

ctrl_c() {
	echo "Purging procs..."
	kill -9 $StationPID
	echo "Done."
	exit $?
}

# trap ctrl-c and call ctrl_c()
trap ctrl_c INT

# Parameter (..., die auch fuer Ihre Loesung interessant sein koennen.)
Team=$1
Station=$2
Message=$3
DataSourcePort=$4
DataSourceIntervall=$5
DataSinkPort=$6
Interface=$7
MCAddress=$8
MCPort=$9
Runtime=$10

# Multicast
# 225.10.1.2
# 15015

if [ $# -gt 6 ] ; then
	if [ "$1" = "--help" ] ; then
		printUsage
	else
        # launch station (use $IfaceName)
		echo "start station $Station..." 
        	java main.Main "$Team" "$Station" "$Message" $MCAddress $MCPort $DataSourcePort $DataSourceIntervall $Interface $DataSinkPort &
        StationPID=$!
		echo "Done!"

        # run...
        sleep $Runtime

		# stop data sink and data source
		echo "Purging procs..."
        kill -9 $StationPID
		echo "Done."

		exit $?
	fi
else
	printUsage
	exit 1
fi
